Part 3

Row

Accidents Map

---
title: "Motor Vehicle Accidents in Victoria"
output: 
  flexdashboard::flex_dashboard:
        vertical_layout: scroll
        orientation: rows
        source_code: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(lubridate)
library(janitor)
library(knitr)
library(kableExtra)
library(ggmap)
library(ggthemes)
library(plotly)
```

```{r load-data}
accidents <- read_csv("data/ACCIDENT.csv") %>%
  clean_names()

locations <- read_csv("data/ACCIDENT_LOCATION.csv") %>%
  clean_names()

nodes <- read_csv("data/NODE.csv") %>%
  clean_names()

persons <- read_csv("data/PERSON.csv") %>%
  clean_names()

vehicles <- read_csv("data/VEHICLE.csv") %>%
  clean_names()
```

```{r create-year-hour-day}
accidents <- accidents %>%
  mutate(accidentdate = dmy(accidentdate),
         Year = year(accidentdate),
         Hour = hour(accidenttime),
         Weekday = wday(accidentdate, 
                        label = TRUE,
                        abbr = FALSE))
```

Part 3 {data-icon="fa-battery-three-quarters"}
===================================== 

Row {.tabset data-height=800}
---------

### **Accidents Map**

```{r accidents-map}
location_box <- c(min(nodes$long), 
                  min(nodes$lat), 
                  max(nodes$long),
                  max(nodes$lat))

location_map <- get_map(location = location_box, 
                        source = 'osm')

  ggmap(location_map) + 
    geom_point(data = nodes,
               aes(x = long,
                   y = lat), 
               colour="#0072B2", 
               alpha=0.5, 
               size = 0.05) +
    theme_map()
```